local bosishi = fk.CreateSkill {
  name = "bosishi",
}

Fk:loadTranslationTable{
  ["bosishi"] = "四世",
  [":bosishi"] = "游戏开始时，所有其他角色各受到你造成的1点火焰伤害，<br>然后这些角色可以依次交给你一张牌并回复1点体力。",
  ["#bosishi-give"] = "硝焰：你可以选择一张牌交给%src来回复1点体力",
  ["$bosishi1"] = "狼烟起四海，鹿奔九州，吾欲麾下分炙。",
  ["$bosishi2"] = "易京有危楼，蓟辽落雪，可焚以驱寒气。",
}

bosishi:addEffect(fk.GameStart, {
  anim_type = "offensive",
  -- 校验玩家拥有技能且存在其他角色
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(bosishi.name) and #player.room:getOtherPlayers(player, false) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:getOtherPlayers(player)
    event:setCostData(self, {tos = tos})
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = room:getOtherPlayers(player)
    
    -- 阶段1：对其他角色造成火焰伤害
    for _, p in ipairs(targets) do
      if not p.dead then
        room:damage{
          from = player,
          to = p,
          damage = 1,
          damageType = fk.FireDamage,
          skillName = bosishi.name,
        }
      end
    end
    
    -- 阶段2：其他角色交牌并回复体力
    for _, p in ipairs(targets) do
      if player.dead then break end  -- 若技能拥有者死亡则中断流程
      if not p.dead then
        -- 询问交牌
        local card = room:askToCards(p, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = bosishi.name,
          cancelable = true,
          prompt = "#bosishi-give:"..player.id,
        })
        -- 处理交牌和回复
        if #card > 0 then
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, bosishi.name, nil, false, p)
          if not p.dead and p:isWounded() then
            room:recover{
              who = p,
              num = 1,
              recoverBy = player,
              skillName = bosishi.name,
            }
          end
        end
      end
    end
  end,
})

return bosishi
